package cn.wolfcode.mq;

import cn.wolfcode.service.ISeckillProductService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = MQConstant.ORDER_RESULT_TOPIC,
        consumerGroup = MQConstant.ORDER_RESULT_TOPIC + "_FAIL_CUSTOMER_GROUP",
        selectorExpression = MQConstant.ORDER_RESULT_FAIL_TAG,
        selectorType = SelectorType.TAG
)
public class MQOrderFailListener implements RocketMQListener<OrderMQResult> {
    @Autowired
    private ISeckillProductService seckillProductService;

    /**
     * 处理秒杀失败的消息
     * @param orderMQResult
     */
    @Override
    public void onMessage(OrderMQResult orderMQResult) {
        seckillProductService.replenishRedisStock(orderMQResult);
    }
}
